/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jfonia.view.main.header;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jfonia.actions.ActionFactory;
import org.jfonia.language.DescriptionConstants;
import org.jfonia.language.LabelConstants;
import org.jfonia.language.LanguageResource;

/**
 *
 * @author Rik Bauwens
 */
public class MenuBar extends JMenuBar
{
        public MenuBar()
        {
                super();
                init();
        }

        private void init()
        {
                ActionFactory actionFactory = ActionFactory.getInstance();
                //File menu
                JMenu fileMenu = new JMenu(LanguageResource.getInstance().getLabel(LabelConstants.FILE));
                fileMenu.getAccessibleContext().setAccessibleDescription(LanguageResource.getInstance().getDescription(DescriptionConstants.FILE));

                JMenuItem newMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.NEWACTION));
                newMenuItem.setIcon(null);
                fileMenu.add(newMenuItem);
                JMenuItem openMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.OPENACTION));
                openMenuItem.setIcon(null);
                fileMenu.add(openMenuItem);
                JMenuItem saveMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.SAVEACTION));
                saveMenuItem.setIcon(null);
                fileMenu.add(saveMenuItem);
                JMenuItem saveAsMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.SAVEASACTION));
                saveAsMenuItem.setIcon(null);
                fileMenu.add(saveAsMenuItem);
                add(fileMenu);

                //Edit menu
                JMenu editMenu = new JMenu(LanguageResource.getInstance().getLabel(LabelConstants.EDIT));
                editMenu.getAccessibleContext().setAccessibleDescription(LanguageResource.getInstance().getDescription(DescriptionConstants.EDIT));

                JMenuItem undoMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.UNDOACTION));
                undoMenuItem.setIcon(null);
                editMenu.add(undoMenuItem);
                JMenuItem redoMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.REDOACTION));
                redoMenuItem.setIcon(null);
                editMenu.add(redoMenuItem);
                editMenu.addSeparator();
                JMenuItem copyMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.COPYACTION));
                copyMenuItem.setIcon(null);
                editMenu.add(copyMenuItem);
                JMenuItem pasteMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.PASTEACTION));
                pasteMenuItem.setIcon(null);
                editMenu.add(pasteMenuItem);
                JMenuItem cutMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.CUTACTION));
                cutMenuItem.setIcon(null);
                editMenu.add(cutMenuItem);
                editMenu.addSeparator();
                JMenuItem newPartMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.NEWPARTACTION));
                newPartMenuItem.setIcon(null);
                editMenu.add(newPartMenuItem);
                editMenu.addSeparator();
                JMenuItem clearMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.CLEARACTION));
                clearMenuItem.setIcon(null);
                editMenu.add(clearMenuItem);
                JMenuItem removeMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.REMOVEACTION));
                removeMenuItem.setIcon(null);
                editMenu.add(removeMenuItem);

                add(editMenu);

                //View menu
                /*JMenu viewMenu = new JMenu(LanguageResource.getInstance().getLabel(LabelConstants.VIEW));
                viewMenu.getAccessibleContext().setAccessibleDescription(LanguageResource.getInstance().getDescription(DescriptionConstants.VIEW));
                JMenuItem notationModeMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.NOTATIONMODEACTION));
                notationModeMenuItem.setIcon(null);
                viewMenu.add(notationModeMenuItem);
                JMenuItem performanceModeMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.PERFORMANCEMODEACTION));
                performanceModeMenuItem.setIcon(null);
                viewMenu.add(performanceModeMenuItem);
                add(viewMenu);*/

                //Tools menu
                JMenu toolsMenu = new JMenu(LanguageResource.getInstance().getLabel(LabelConstants.TOOLS));
                toolsMenu.getAccessibleContext().setAccessibleDescription(LanguageResource.getInstance().getDescription(DescriptionConstants.TOOLS));
                final JMenuItem playOrPauseMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.PLAYORPAUSEACTION));
                playOrPauseMenuItem.setIcon(null);
                toolsMenu.add(playOrPauseMenuItem);
                playOrPauseMenuItem.addChangeListener(new ChangeListener()
                {
                        public void stateChanged(ChangeEvent e)
                        {
                                playOrPauseMenuItem.setIcon(null);
                        }
                });
                JMenuItem stopMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.STOPACTION));
                stopMenuItem.setIcon(null);
                toolsMenu.add(stopMenuItem);
                JMenuItem tappingMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.TAPPINGACTION));
                tappingMenuItem.setIcon(null);
                toolsMenu.add(tappingMenuItem);
                add(toolsMenu);

                //Help menu
                JMenu helpMenu = new JMenu(LanguageResource.getInstance().getLabel(LabelConstants.HELP));
                helpMenu.getAccessibleContext().setAccessibleDescription(LanguageResource.getInstance().getDescription(DescriptionConstants.HELP));
                JMenuItem errorConsoleMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.ERRORCONSOLEACTION));
                errorConsoleMenuItem.setIcon(null);
                helpMenu.add(errorConsoleMenuItem);
                JMenuItem resourcesMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.RESOURCESACTION));
                resourcesMenuItem.setIcon(null);
                helpMenu.add(resourcesMenuItem);
                JMenuItem helpMenuItem = new JMenuItem(actionFactory.getAction(ActionFactory.HELPACTION));
                helpMenuItem.setIcon(null);
                helpMenu.add(helpMenuItem);

                add(helpMenu);
        }
}
